package com.infomanage.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.jiuqi.util.StringUtils;

public class TimeUtil {

	public static String showCurrentTime() {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd/HH:mm");
		String nowTime = format.format(new Date());
		return nowTime;
	}

	public static String showCurrentCNTime(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日E");
		String nowTime = format.format(new Date());
		return nowTime;
	}
	
	public static String showCurrentYear(){
		return parseToYear(showCurrentTime());
	}
	public static String showCurrentDay() {
		return showCurrentTime().split("/")[0];
	}

	public static String showCurrentHour() {
		return showCurrentTime().split("/")[1].split(":")[0];
	}

	public static String showCurrentMinute() {
		return showCurrentTime().split("/")[1].split(":")[1];
	}

	public static String parseToYear(String fullTime) {
		if(fullTime.contains("/")){
			String[] array1 = fullTime.split("/");
			String[] array2 = array1[0].split("-");
			return array2[0];
		}
		
		return null;
	}

	public static String parseToMonth(String fullTime) {
		if(fullTime.contains("/")){
			String[] array1 = fullTime.split("/");
			String[] array2 = array1[0].split("-");
			return array2[1];
		}
		
		return "";
	}

	public static String parseToYearMonth(String fullTime){
		try {
			fullTime = fullTime.substring(0, fullTime.indexOf(";"));
				String[] array2 = fullTime.split("-");
				return array2[0] + "-" +  array2[1];
		} catch (Exception e) {
			return "";
		}
	}
	
	public static String toFullTime(String timeStr){
		if(timeStr == null)
			return "";
		StringBuffer sb = new StringBuffer();
		if(timeStr.contains(";")){
			String[] timeArray = timeStr.split(";");
			if(timeArray.length == 3){
				if(StringUtils.isEmpty(timeArray[0])){
					return "";
				}
				sb.append(timeArray[0]);
				sb.append("/");
				sb.append(timeArray[1]);
				sb.append(":");
				sb.append(timeArray[2]);
			}
		}else{
			sb.append(timeStr);
		}
		return sb.toString();
	}
	public static String toDayTime(String timeStr){
		if(timeStr == null)
			return "";
		StringBuffer sb = new StringBuffer();
		if(timeStr.contains(";")){
			String[] timeArray = timeStr.split(";");
			if(timeArray.length == 3){
				sb.append(timeArray[0]);
			}
		}else{
			sb.append(timeStr);
		}
		return sb.toString();
	}
	public static String toHourTime(String timeStr){
		if(timeStr == null)
			return "";
		StringBuffer sb = new StringBuffer();
		if(timeStr.contains(";")){
			String[] timeArray = timeStr.split(";");
			if(timeArray.length == 3){
				sb.append(timeArray[1]);
			}
		}else{
			sb.append(timeStr);
		}
		return sb.toString();
	}
	public static String toMinuteTime(String timeStr){
		if(timeStr == null)
			return "";
		StringBuffer sb = new StringBuffer();
		if(timeStr.contains(";")){
			String[] timeArray = timeStr.split(";");
			if(timeArray.length == 3){
				sb.append(timeArray[2]);
			}
		}else{
			sb.append(timeStr);
		}
		return sb.toString();
	}
	
	public static String[] get24Hours(){
		return new String[]{
			"01", "02", "03",
			"04", "05", "06",
			"07", "08", "09",
			"10", "11", "12",
			"13", "14", "15",
			"16", "17", "18",
			"19", "20", "21",
			"22", "23", "24"
		};
	}
	
	public static String[] get60Minutes(){
		String minute = "";
		String[] minutes = new String[60];
		for(int i = 0; i < 60; i++){
			minute = String.valueOf(i);
			if(i < 10){
				minute = "0" + i;
			}
			minutes[i] = minute;
		}
		return minutes;
	}
	public static void main(String[] args){
	}
}

